// tome.txt
// A script for simple books on pedestals,
// bookcases or boxes with scrolls that teach
// spells or alchemy.
// Memory Cells:
// 0 - 0 for mage, 1 for priest, 2 for alchemy.
// 1 - Number of spell/recipe.
// 2 - Level of spell.
// 3,4 - SDF.

beginterrainscript;
variables;

int i = 0, choice;
string learn;
body;
beginstate INIT_STATE;
    clear_buffer();
    append_string("It's a magic describition, and you can understand it. Now you have read about the");
    if (get_memory_cell(0) == 0)
    {
        if (get_memory_cell(1) == 0)
            append_string(" mage spell Bolt of Fire");
        if (get_memory_cell(1) == 1)
            append_string(" mage spell Light");
        if (get_memory_cell(1) == 2)
            append_string(" mage spell Call Beast");
        if (get_memory_cell(1) == 3)
            append_string(" mage spell Spray Acid");
        if (get_memory_cell(1) == 4)
            append_string(" mage spell Haste");
        if (get_memory_cell(1) == 5)
            append_string(" mage spell Slow");
        if (get_memory_cell(1) == 6)
            append_string(" mage spell Ice Lances");
        if (get_memory_cell(1) == 7)
            append_string(" mage spell Unlock Doors");
        if (get_memory_cell(1) == 8)
            append_string(" mage spell Create Illusions");
        if (get_memory_cell(1) == 9)
            append_string(" mage spell Far Sight");
        if (get_memory_cell(1) == 10)
            append_string(" mage spell Lightning Spray");
        if (get_memory_cell(1) == 11)
            append_string(" mage spell Capture Mind");
        if (get_memory_cell(1) == 12)
            append_string(" mage spell Simularcum");
        if (get_memory_cell(1) == 13)
            append_string(" mage spell Dispel Barrier");
        if (get_memory_cell(1) == 14)
            append_string(" mage spell Summon Aid");
        if (get_memory_cell(1) == 15)
            append_string(" mage spell Forcecage");
        if (get_memory_cell(1) == 16)
            append_string(" mage spell Fireblast");
        if (get_memory_cell(1) == 17)
            append_string(" mage spell Arcane Summon");
        if (get_memory_cell(1) == 18)
            append_string(" mage spell Arcane Shield");
        if (get_memory_cell(1) == 19)
            append_string(" mage spell Arcane Blow");
        append_string(" at level ");
        append_num(get_memory_cell(2));
    }
    if (get_memory_cell(0) == 1)
    {
        if (get_memory_cell(1) == 0)
            append_string(" priest spell Healing");
        if (get_memory_cell(1) == 1)
            append_string(" priest spell Curing");
        if (get_memory_cell(1) == 2)
            append_string(" priest spell War Blessing");
        if (get_memory_cell(1) == 3)
            append_string(" priest spell Terror");
        if (get_memory_cell(1) == 4)
            append_string(" priest spell Repel Spirit");
        if (get_memory_cell(1) == 5)
            append_string(" priest spell Smite");
        if (get_memory_cell(1) == 6)
            append_string(" priest spell Summon Shade");
        if (get_memory_cell(1) == 7)
            append_string(" priest spell Enduring Barrier");
        if (get_memory_cell(1) == 8)
            append_string(" priest spell Unshackle Mind");
        if (get_memory_cell(1) == 9)
            append_string(" priest spell Move Mountains");
        if (get_memory_cell(1) == 10)
            append_string(" priest spell Mass Healing");
        if (get_memory_cell(1) == 11)
            append_string(" priest spell Mass Curing");
        if (get_memory_cell(1) == 12)
            append_string(" priest spell Radiant Shield");
        if (get_memory_cell(1) == 13)
            append_string(" priest spell Divine Fire");
        if (get_memory_cell(1) == 14)
            append_string(" priest spell Control Foes");
        if (get_memory_cell(1) == 15)
            append_string(" priest spell Cloud of Blades");
        if (get_memory_cell(1) == 16)
            append_string(" priest spell Return Life");
        if (get_memory_cell(1) == 17)
            append_string(" priest spell Divine Retribution");
        if (get_memory_cell(1) == 18)
            append_string(" priest spell Divine Restoration");
        if (get_memory_cell(1) == 19)
            append_string(" priest spell Divine Host");
        append_string(" at level ");
        append_num(get_memory_cell(2));
    }
    if (get_memory_cell(0) == 2)
    {
        if (get_memory_cell(1) == 0)
            append_string(" alchemy recipe for making Healing Potion.");
        if (get_memory_cell(1) == 1)
            append_string(" alchemy recipe for making Curing Potion.");
        if (get_memory_cell(1) == 2)
            append_string(" alchemy recipe for making Hasting Potion.");
        if (get_memory_cell(1) == 3)
            append_string(" alchemy recipe for making Energy Potion.");
        if (get_memory_cell(1) == 4)
            append_string(" alchemy recipe for making Strength Potion.");
        if (get_memory_cell(1) == 5)
            append_string(" alchemy recipe for making Graymold Salve.");
        if (get_memory_cell(1) == 6)
            append_string(" alchemy recipe for making Balm of Life.");
        if (get_memory_cell(1) == 7)
            append_string(" alchemy recipe for making Healing Elixir.");
        if (get_memory_cell(1) == 8)
            append_string(" alchemy recipe for making Hasting Elixir.");
        if (get_memory_cell(1) == 9)
            append_string(" alchemy recipe for making Energy Elixir.");
        if (get_memory_cell(1) == 10)
            append_string(" alchemy recipe for making Rogue's Elixir.");
        if (get_memory_cell(1) == 11)
            append_string(" alchemy recipe for making Strength Elixir.");
        if (get_memory_cell(1) == 12)
            append_string(" alchemy recipe for making Bliss Elixir.");
        if (get_memory_cell(1) == 13)
            append_string(" alchemy recipe for making Restoration Brew.");
        if (get_memory_cell(1) == 14)
            append_string(" alchemy recipe for making Protection Brew.");
        if (get_memory_cell(1) == 15)
            append_string(" alchemy recipe for making Heroic Brew.");
        if (get_memory_cell(1) == 16)
            append_string(" alchemy recipe for making Invulnerability Potion.");
    }
    get_text_buffer(learn);
break;
beginstate SEARCH_STATE;
if ((get_memory_cell(3) != 0) || (get_memory_cell(4) != 0))
if ((get_flag(get_memory_cell(3), get_memory_cell(4)) == 1))
if (get_memory_cell(0) == 2)
    end();
else while (i < 6)
{
    if (get_spell_level(i, get_memory_cell(0), get_memory_cell(1)) >= get_memory_cell(2))
        end();
    i = i + 1;
}
    
    reset_dialog();
    if (terrain_in_this_spot() == 217)
        add_dialog_str(0, "You have found an interesting book, clearly placed on the pedestal for people who read lots. It looks magical. Care to read it?", 0);
    else add_dialog_str(0, "Among the big, boring history tomes, you find an interesting book. It looks magical. Care to read it?", 0);
    add_dialog_choice(0, "No.");
    add_dialog_choice(1, "Sure.");
    choice = run_dialog(0);
    i = 0;
    if (choice == 2)
    {
        if (get_memory_cell != 2)
        while (i < 6)
        {
            while (get_spell_level(i, get_memory_cell(0), get_memory_cell(1)) =< get_memory_cell(2))
                change_spell_level(i, get_memory_cell(0), get_memory_cell(1), 1);
            i = i + 1;
        }
        else give_recipe(get_memory_cell(1));
        message_dialog(learn, ""); 
        if ((get_memory_cell(3) != 0) || (get_memory_cell(4) != 0))
            set_flag(get_memory_cell(3), get_memory_cell(4), 1);
break;